<?php include TMPL_PATH.'public/header.phtml';?>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/jscal2.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/border-radius.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/win2k.css"/>
<script type="text/javascript" src="/statics/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/statics/js/calendar/lang/zh-cn.js"></script>
<div class="subnav">
    <div class="content-menu ib-a blue line-x">
    	<div style="float:left;margin-right:50px;">
        <a href='javascript:;' class="on"><em>订单列表</em></a>
     </div>
    	<div style="color:#000;">
			<div style="float:left;">
    		<form name="searchform" action="<?php echo U('order/cart_product');?>"  method="post">
    		<input type="hidden" value="1" name="search">
			<input type="hidden" value="<?php echo $pageRows; ?>" name="pageRows">
				&nbsp;&nbsp;&nbsp;<select name="searchtype" id="searchtype" >
					<option <?php if($searchtype==0)echo 'selected';?> value="0">用户邮箱</option>
					<option value="1" <?php if($searchtype==1)echo 'selected';?>>sid</option>
				</select>
				<input type="text" class="input-text" value="<?php echo $searchkeyword;?>" name="keyword"  id="keyword" />
                
			   &nbsp;&nbsp;&nbsp;用户类型: <select name="usertype" id="usertype">
					<option <?php if($usertype==1)echo 'selected';?> value="1">注册用户</option>
					<option value="2" <?php if($usertype==2)echo 'selected';?>>全部</option>
					<option value="3" <?php if($usertype==3)echo 'selected';?>>游客</option>
				</select>
				

				&nbsp;&nbsp;&nbsp;&nbsp;
                语言：<select name="language" id="language">
				 <option value="0">请选择</option>
					<?php 
						if(isset($languageList) && $languageList):
							foreach ($languageList as $key => $val):
						?>
						    <option value="<?php echo $key?>" <?php if($language==$key)echo 'selected';?> ><?php echo $val;?></option>
						<?php 
							endforeach;
						endif;
						?>
				</select>
				&nbsp;&nbsp;&nbsp;&nbsp;
				    更新时间:
				    <input class="input-text" name="start_time" type="text" id="start_time" size="22" value="<?php echo $start_time;?>" />
				    <script type="text/javascript">
						Calendar.setup({
						weekNumbers: false,
					    inputField : "start_time",
					    trigger    : "start_time",
					    dateFormat: "%Y-%m-%d",
					    showTime: false,
					    minuteStep: 1,
					    onSelect   : function() {this.hide();}
						});
				    </script>
				    至:<input class="input-text"  name="end_time" type="text" id="end_time" size="22" value="<?php echo $end_time;?>" />
					<script type="text/javascript">
						Calendar.setup({
						weekNumbers: false,
					    inputField : "end_time",
					    trigger    : "end_time",
					    dateFormat: "%Y-%m-%d",
					    showTime: false,
					    minuteStep: 1,
					    onSelect   : function() {this.hide();}
						});
					</script>
                   &nbsp;&nbsp;&nbsp;&nbsp;
					<input type="submit" value="搜索" class="button" name="search">
    		</form>
			</div>
			<div style="float:right;">
                 <a href="javascript:carProductExcel();">导出Excel</a>
			</div>
    	</div>
    </div>
</div>
<div class="bk"></div>
<div class="pad_10">
<div class="table-list">
    <table width="100%" cellspacing="0" >
        <thead>
            <tr>
            <th width="15%">用户邮箱</th>
            <th align='center' width="20%">商品数量</th>
            <th align='center' width="15%">购物车总金额</th>
            <th align='center' width="20%">更新时间</th>
            <th align='center' width="15%">备注</th>
			<th>管理操作</th>
            </tr>
        </thead>
    <tbody>
    <?php
   	if(isset($cartList) && $cartList):
   		foreach ($cartList as $k=>$v):
    ?>
			<tr>
				<td align='center'>
					<?php echo !empty($v['email']) ? $v['email'] : '游客'; ?>
					<?php if($v['user_id']>0){echo "<br />用户语言：".$v['language'];};?>
				</td>
				<td align='center'><?php echo "商品种类: ".$v['counts']."<br />商品件数: ".$v['qtys']."";?></td>
				<td align='center'><?php echo $v['productList']['total_amount'];?></td>
				<td align='center'><?php echo date('Y-m-d H:i:s',$v['add_time']);?></td>
				<td align='center'><?php if($v['user_id']>0){echo "用户ID：".$v['user_id'];}else{echo 'sid:'.$v['sidss'];};?></td>
				<td align='center'><a href="javascript:void(0);" onclick="cartListShow(this,<?php echo $k; ?>);" class="as" >展开</a></td>
			</tr>
			<?php
			if(isset($v['productList']['productList'])):
			?>
				<tr style="display:none;" id="tr_<?php echo $k; ?>" class="trs">
				<td colspan="6">
				    <table width="100%" cellspacing="0" >
				        <thead>
				            <tr>
				            <th align='center' width="15%">商品编码</th>
				            <th align='left' width="30%">商品信息</th>
				            <th align='center' width="15%">商品数量</th>
				            <th align='center' width="10%">单价</th>
				            <th align='center' width="10%">合计</th>
                            <th align='center' width="10%">加入时间</th>
                            <th align='center' width="10%">是否绑定<br />身型数据</th>
				            </tr>
				        </thead>
				    <tbody>
				    <?php
				   		foreach ($v['productList']['productList'] as $vp):
				    ?>
						<tr>
							<td align='center'>
							<?php echo "编码: ".$vp['product']['sn']."";?>
                            <br />
                            <?php echo "商品ID: ".$vp['pid']."";?>
                            </td>
							<td align='left'>
								<a href="<?php echo $vp['product']['url'];?>" target="_blank" style="margin-right:10px;"><img src="<?php echo $vp['product']['small_img']; ?>" /></a>
							    <a href="<?php echo $vp['product']['url'];?>" target="_blank" style="margin-right:10px;"><?php echo isset($vp['product']['name']) ? $vp['product']['name'] : null ?></a>
							    <br />
							    中文名称:<?php echo isset($vp['product']['name_cn']) ? $vp['product']['name_cn'] : null ?>
						    </td>
							<td align='center'><?php echo "".$vp['qty']."";?></td>
							<td align='center'><?php echo $vp['product']['price']."";?></td>
							<td align='center'><?php echo $vp['goods_amount']."";?></td>
                            <td align='center'><?php echo date('Y-m-d H:i:s',$vp['add_time']);?></td>
                            <td align='center'><?php if($vp['measure_id']){echo "已绑定身型数据";
                                $m_status =  M('user_measure')->field('m_status')->where('id='.$vp['measure_id'])->find();
                                switch($m_status['m_status']){
                                    case 1:
                                       echo '(量尺量体)';break;
                                    case 2:
                                       echo '(免量体)'; break;
                                    case 3:
                                        echo '(拍照量体)';break;
                                    case 4:
                                        echo '(量尺并拍照)'; break; 
								    case 5:
                                        echo '(选尺码购物)'; break;  		       
                               }
                            }?></td>
						</tr>
                       <?php
                        if($vp['pants_qty'] > 0){
					   ?>
						<tr>
							<td align='center'></td>
							<td align='left'>
                                <?php echo isset($vp['product']['name_cn']) ? $vp['product']['name_cn'] : null ?> - 同款单裤
						    </td>
							<td align='center'><?php echo $vp['pants_qty'];?></td>
							<td align='center'><?php echo $vp['add_pants']['price'];?></td>
							<td align='center'><?php echo $vp['add_pants']['price'] * $vp['pants_qty'];?></td>
                            <td align='center'></td>
                            <td align='center'></td>
						</tr> 
                        <?php } ?>      
					<?php 
						endforeach;
					?>
					<tr>
						<td align='center' colspan="7" style="height:15px"> </td>
					</tr>
					</tbody>
                    </table>
				</td>
				</tr>
			<?php 
				endif;
			?>
	<?php 
		endforeach;
		endif;
	?>
   </tbody>
    </table>
<div id="pages"><?php echo $pageShow;?></div>
</div>
</div>
</body>
</html>
<script type="text/javascript">

function cartListShow(obj,id){
    if($(obj).text() == '关闭'){
        $('#tr_'+id).hide();$(obj).text('展开'); 
    }else{
    	$('.trs').hide();$('.as').text('展开')
		if($('#tr_'+id).css('display')=='none'){
	        $('#tr_'+id).show();$(obj).text('关闭'); 
	    }else{
	    	$('#tr_'+id).hide();$(obj).text('展开'); 
	    }
    }
}

function carProductExcel(){
    var hrefstr ="<?php echo U('order/cart_product');?>"
                     +"&doexcel=1"
                     +"&searchtype="+$('#searchtype').val()
                     +"&keyword="+$('#keyword').val()
                     +"&usertype="+$('#usertype').val()
                     +"&language="+$('#language').val()
                     +"&start_time="+$('#start_time').val()
                     +"&end_time="+$('#end_time').val();
    location.href = hrefstr;
}
</script>